import React, { useCallback, useState } from "react";
import Child3 from "../components/Child3";

export default function UseCallBack() {
  const [num, setnum] = useState(10);
  const [n, setn] = useState(1)

  let  fn  = useCallback(()=>{
            console.log(n+"发生了改变");
  },[n]);

  return (
    <div>
      UseCallBack
      <div>
        显示数据{num}
        <button
          onClick={() => {
            setnum(num + 1);
          }}
        >
          修改数据
        </button>{" "}
      </div>
      <div>
        数据n为{n}
        <button onClick={()=>{
            setn(n+1);
        }}>修改n</button>
      </div>
      <hr />
      <Child3 fn={fn}></Child3>
    </div>
  );
}
